/**
 * Copyright (C) Skywares Information Technology, LTD. 
 * All Rights Reserved.
 *
 * OrderDao.java created on 2020年2月4日 下午7:29:44 by Lyon Lu 
 */
package com.mvc.server.miaosha.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;

import com.mvc.server.miaosha.pojo.MiaoshaOrder;
import com.mvc.server.miaosha.pojo.OrderInfo;

/**
 * <pre>
 * Description:
 * 
 * @author Lyon Lu
 * @date 2020年2月4日 下午7:29:44
 *
 * </pre>
 */
@Mapper
public interface OrderDao {

	@Select("select * from miaosha_order where user_id=#{userId} and goods_id=#{goodsId}")
	MiaoshaOrder getMiaoshaOrderByUserIdGoodsId(@Param("userId")long userId, @Param("goodsId")long goodsId);

	@Insert("insert into order_info(user_id, goods_id, goods_name, goods_count, goods_price, order_channel, status, create_date)values("
			+ "#{userId}, #{goodsId}, #{goodsName}, #{goodsCount}, #{goodsPrice}, #{orderChannel},#{status},#{createDate} )")
	@SelectKey(keyColumn="id", keyProperty="id", resultType=long.class, before=false, statement="select last_insert_id()")
	long insert(OrderInfo orderInfo);
	
	@Insert("insert into miaosha_order (user_id, goods_id, order_id)values(#{userId}, #{goodsId}, #{orderId})")
	int insertMiaoshaOrder(MiaoshaOrder miaoshaOrder);

	@Select("select * from order_info where id = #{orderId}")
	OrderInfo getOrderById(@Param("orderId")long orderId);

	@Delete("delete from order_info")
	void deleteOrders();

	@Delete("delete from miaosha_order")
	void deleteMiaoshaOrders();

	@Select("select * from miaosha_order where goods_id=#{goodsId}")
	List<MiaoshaOrder> listByGoodsId(@Param("goodsId") long goodsId);

}
